import request from "@/utils/api";

const BASE_URL = "/product/category";

const ProductCategoryAPI = {
  getCategoryTreeList(): Promise<Category[]> {
    return request<any, Category[]>({
      url: `${BASE_URL}/getCategoryTreeList`,
      method: "get",
    });
  },

  removeMenuByIds(ids: string[]): Promise<void> {
    return request<any, void>({
      url: `${BASE_URL}/removeMenuByIds`,
      method: "post",
      data: ids,
    });
  },

  addCategory(category: Category): Promise<void> {
    return request<any, void>({
      url: `${BASE_URL}/addCategory`,
      method: "post",
      data: category,
    });
  },

  updateCategory(category: Category): Promise<void> {
    return request<any, void>({
      url: `${BASE_URL}/updateCategory`,
      method: "post",
      data: category,
    });
  },

  getCategoryById(catId: string): Promise<Category> {
    return request<any, Category>({
      url: `${BASE_URL}/getCategoryById/${catId}`,
      method: "get",
    });
  },

  updateCategoryList(categoryList: Category[]): Promise<void> {
    return request<any, void>({
      url: `${BASE_URL}/updateCategoryList`,
      method: "post",
      data: categoryList,
    });
  },
};

export default ProductCategoryAPI;

export interface Category {
  /**
   * 分类id
   */
  catId?: string | number | null;
  /**
   * 分类名称
   */
  name?: string;
  /**
   * 父分类id
   */
  parentCid?: string | number;
  /**
   * 层级
   */
  catLevel?: string | number;
  /**
   * 是否显示[0-不显示，1显示]
   */
  showStatus?: string | number;
  /**
   * 排序
   */
  sort?: string | number;
  /**
   * 图标地址
   */
  icon?: string;
  /**
   * 计量单位
   */
  productUnit?: string;
  /**
   * 商品数量
   */
  productCount?: string | number;
  /**
   * 子节点
   */
  children?: Category[];
}
